package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modelo.Login;

public class ControllerRealizarLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ControllerRealizarLogin() {
        super();
        // TODO Auto-generated constructor stub
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		Login lg = new Login();
		
		lg.setUsuario(request.getParameter("user"));
		lg.setSenha(request.getParameter("pass"));

		if (lg.login() == false)
		{
			response.sendRedirect("Erro.jsp");
		} 
		else
		{
			if(lg.login() == true)
			{
				request.getSession().setAttribute("login", lg.getUsuario());
				//response.sendRedirect("Menu.jsp"); 				
				//response.sendRedirect("protected/fc");
				response.sendRedirect("Principal.jsp");
			}
		}
	}
}

